home *** CD-ROM | disk | FTP | other *** search
/ Aminet 37 / Aminet 37 (2000)(Schatztruhe)[!][Jun 2000].iso / Aminet / dev / lang / sofa.lha / sofa / smalleiffel / lib_se / command_flags.e < prev    next >
Text File  |  2000-03-25  |  8KB  |  280 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr
  4. --                       http://SmallEiffel.loria.fr
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License
  11. -- for  more  details.  You  should  have  received a copy of the GNU General
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. deferred class COMMAND_FLAGS
  17.    --
  18.    -- Some useful tools to handle command flags (inherited by compile,
  19.    -- compile_to_c, compile_to_jvm, finder, clean, short, pretty, etc.).
  20.    --
  21.  
  22. inherit GLOBALS;
  23.  
  24. feature {NONE}
  25.  
  26.    Command_compile_to_c:    STRING is "compile_to_c";
  27.  
  28.    Command_clean:           STRING is "clean";
  29.  
  30.    command_name: STRING is
  31.       deferred
  32.       end;
  33.  
  34.    search_for_verbose_flag is
  35.          -- To become verbose as soon as possible.
  36.       local
  37.          i: INTEGER;
  38.       do
  39.          from
  40.             i := argument_count;
  41.          until
  42.             i = 0
  43.          loop
  44.             if is_flag_verbose(argument(i)) then
  45.                echo.set_verbose;
  46.                i := 0;
  47.             else
  48.                i := i - 1;
  49.             end;
  50.          end;
  51.       end;
  52.  
  53.    search_for_cc_flag(argc: INTEGER) is
  54.          -- To know about the C compiler as soon as possible.
  55.       local
  56.          i: INTEGER;
  57.          c_compiler: STRING;
  58.       do
  59.          from
  60.             i := 1;
  61.          until
  62.             i > argc
  63.          loop
  64.             if Flag_cc.is_equal(argument(i)) then
  65.                if i < argc then
  66.                   i := i + 1;
  67.                   c_compiler := argument(i);
  68.                   i := argc + 1;
  69.                end;
  70.             end;
  71.             i := i + 1;
  72.          end;
  73.          system_tools.set_c_compiler(c_compiler);
  74.       end;
  75.  
  76.    is_flag_case_insensitive(flag: STRING): BOOLEAN is
  77.       do
  78.          if ("-case_insensitive").is_equal(flag) then
  79.             Result := true;
  80.             eiffel_parser.set_case_insensitive;
  81.          end;
  82.       end;
  83.  
  84.    is_flag_no_style_warning(flag: STRING): BOOLEAN is
  85.       do
  86.          if ("-no_style_warning").is_equal(flag) then
  87.             Result := true;
  88.             eiffel_parser.set_no_style_warning;
  89.          end;
  90.       end;
  91.  
  92.    is_flag_no_warning(flag: STRING): BOOLEAN is
  93.       do
  94.          if ("-no_warning").is_equal(flag) then
  95.             Result := true;
  96.             eh.set_no_warning;
  97.          end;
  98.       end;
  99.  
  100.    is_flag_trace(flag: STRING): BOOLEAN is
  101.       do
  102.          if ("-trace").is_equal(flag) then
  103.             Result := true;
  104.             run_control.set_trace;
  105.          end;
  106.       end;
  107.  
  108.    is_flag_verbose(flag: STRING): BOOLEAN is
  109.       do
  110.          if ("-verbose").is_equal(flag) then
  111.             Result := true;
  112.          end;
  113.       end;
  114.  
  115.    is_flag_version(flag: STRING): BOOLEAN is
  116.       do
  117.          if ("-version").is_equal(flag) then
  118.             Result := true;
  119.             std_output.put_string("Version of command %"");
  120.             std_output.put_string(command_name);
  121.             std_output.put_string("%" is:%N");
  122.             std_output.put_string(small_eiffel.copyright);
  123.             if argument_count = 1 then
  124.                die_with_code(exit_success_code);
  125.             end;
  126.          end;
  127.       end;
  128.  
  129.    is_flag_boost(flag: STRING): BOOLEAN is
  130.       do
  131.          if ("-boost").is_equal(flag) then
  132.             Result := true;
  133.             run_control.set_boost;
  134.             check_for_level(flag);
  135.          end;
  136.       end;
  137.  
  138.    is_flag_no_check(flag: STRING): BOOLEAN is
  139.       do
  140.          if ("-no_check").is_equal(flag) then
  141.             Result := true;
  142.             run_control.set_no_check;
  143.             check_for_level(flag);
  144.          end;
  145.       end;
  146.  
  147.    is_flag_require_check(flag: STRING): BOOLEAN is
  148.       do
  149.          if ("-require_check").is_equal(flag) then
  150.             Result := true;
  151.             run_control.set_require_check;
  152.             check_for_level(flag);
  153.          end;
  154.       end;
  155.  
  156.    is_flag_ensure_check(flag: STRING): BOOLEAN is
  157.       do
  158.          if ("-ensure_check").is_equal(flag) then
  159.             Result := true;
  160.             run_control.set_ensure_check;
  161.             check_for_level(flag);
  162.          end;
  163.       end;
  164.  
  165.    is_flag_invariant_check(flag: STRING): BOOLEAN is
  166.       do
  167.          if ("-invariant_check").is_equal(flag) then
  168.             Result := true;
  169.             run_control.set_invariant_check;
  170.             check_for_level(flag);
  171.          end;
  172.       end;
  173.  
  174.    is_flag_loop_check(flag: STRING): BOOLEAN is
  175.       do
  176.          if ("-loop_check").is_equal(flag) then
  177.             Result := true;
  178.             run_control.set_loop_check;
  179.             check_for_level(flag);
  180.          end;
  181.       end;
  182.  
  183.    is_flag_all_check(flag: STRING): BOOLEAN is
  184.       do
  185.          if ("-all_check").is_equal(flag) then
  186.             Result := true;
  187.             run_control.set_all_check;
  188.             check_for_level(flag);
  189.          end;
  190.       end;
  191.  
  192.    is_flag_debug_check(flag: STRING): BOOLEAN is
  193.       do
  194.          if ("-debug_check").is_equal(flag) then
  195.             Result := true;
  196.             run_control.set_debug_check;
  197.          end;
  198.       end;
  199.  
  200.    is_flag_cecil(flag: STRING; argi, argc: INTEGER): BOOLEAN is
  201.       do
  202.          if ("-cecil").is_equal(flag) then
  203.             Result := true;
  204.             if argi < argc then
  205.                run_control.set_cecil_path(argument(argi + 1));
  206.             else
  207.                echo.w_put_string(command_name);
  208.                echo.w_put_string(" : missing file name after -cecil flag.%N");
  209.                die_with_code(exit_failure_code);
  210.             end;
  211.          end;
  212.       end;
  213.  
  214.    is_flag_o(flag: STRING; argi, argc: INTEGER;
  215.              code_printer: CODE_PRINTER): BOOLEAN is
  216.       local
  217.          output_name: STRING;
  218.       do
  219.          if ("-o").is_equal(flag) then
  220.             Result := true;
  221.             if argi < argc then
  222.                output_name := argument(argi + 1);
  223.                if output_name.has_suffix(eiffel_suffix) then
  224.                   echo.w_put_string("Bad executable name: %"");
  225.                   echo.w_put_string(output_name);
  226.                   echo.w_put_string(
  227.                   "%". Must not use Eiffel source file suffix %
  228.                    %with option %"-o <executable_name>%".");
  229.                   die_with_code(exit_failure_code);
  230.                end;
  231.                run_control.set_output_name(output_name);
  232.             else
  233.                echo.w_put_string(command_name);
  234.                echo.w_put_string(" : missing output name after -o flag.%N");
  235.                die_with_code(exit_failure_code);
  236.             end;
  237.          end;
  238.       end;
  239.  
  240.    check_for_root_class is
  241.       do
  242.          if run_control.root_class = Void then
  243.             echo.w_put_string(command_name);
  244.             echo.w_put_string(": error: No <Root-Class> in command line.%N");
  245.             die_with_code(exit_failure_code);
  246.          end;
  247.       end;
  248.  
  249.    level_flag: STRING;
  250.  
  251.    check_for_level(new_level_flag: STRING) is
  252.       do
  253.          if level_flag /= Void then
  254.             if not level_flag.is_equal(new_level_flag) then
  255.                echo.w_put_string(command_name);
  256.                echo.w_put_string(": level is already set to ");
  257.                echo.w_put_string(level_flag);
  258.                echo.w_put_string(". Bad flag ");
  259.                echo.w_put_string(new_level_flag);
  260.                echo.w_put_string(fz_dot);
  261.                die_with_code(exit_failure_code);
  262.             end;
  263.          else
  264.             level_flag := new_level_flag;
  265.          end;
  266.       end;
  267.  
  268.    unknown_flag_exit(flag: STRING) is
  269.       do
  270.          echo.w_put_string(command_name);
  271.          echo.w_put_string(" : unknown flag %"");
  272.          echo.w_put_string(flag);
  273.          echo.w_put_string("%".%N");
  274.          die_with_code(exit_failure_code);
  275.       end;
  276.  
  277.    Flag_cc: STRING is "-cc";
  278.  
  279. end -- COMMAND_FLAGS
  280.